#include "texture_manager.h"
#include "../../platform/image.h"

namespace jlib {


Texture *TextureManager::get (const std::string &path, FileDomain domain) noexcept {
  auto helper = getHelper();
  auto name = helper->getAbsolutePath(path.c_str(), domain);
  auto &ptr = this->_cache[name];
  if (ptr)
    return ptr;
  auto tex = Image::loadImage(path.c_str(), domain);
  if (!tex)
    return nullptr;
  return ptr = tex;
}


void TextureManager::clear () noexcept {
  this->_cache.clear();
}


} // namespace jlib
